<%@ LANGUAGE = VBScript.Encode %>
<%
	Session("FormName")="F29"
%>
<!--#include file="CVUnicode.inc"-->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<META content=no-cache http-equiv=Pragma>
<META content=no-cache http-equiv=Cache-Control>
<meta name="GENERATOR" content="Microsoft FrontPage 5.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<title></title>
</head>
<body style="font-family: Times New Roman" topmargin=5 leftmargin=5>
<html>
<body bgcolor="#F8F9D9">
<%
  'On Error resume next
  Server.ScriptTimeOut =20
  Dim bArray()
  Call LoadData(bArray, "vnucode")
  function Subst (strValue, strOldValue, strNewValue)
    intLoc = InStr(strValue, strOldValue)
    While intLoc > 0
      if intLoc > 1 then
        if intLoc = Len(strValue) then
          strValue = Left(strValue, intLoc-1) & strNewValue
        else
          strValue = Left(strValue, intLoc -1) & strNewValue & Right(strValue, Len(strValue)-(intLoc-Len(strOldValue)+1))
        end if
      else
        strValue = strNewValue & Right(strValue, Len(strValue)-1)
      end if
      intLoc = InStr(strValue, strOldValue)
    Wend
    Subst = strValue
  end function

  function FixUpItems (strItem)
    if strItem <> "" then
      strItem = Subst(strItem, "<", "&lt;")
      strItem = Subst(strItem, ">", "&gt;")
      FixUpItems = strItem
    else
      FixUpItems = "<br>"
    end if
  end function

  rem ******************************************
  rem * Shows a form for the user to fill in
  rem *  host, uid and pwd.
  rem ******************************************
  
  sub ShowPopForm (strHostName, strUser, strPassword)
    Response.Write "<table border=0>"
    Response.Write "<form action=""Openmail.asp"" method=post>"
    Response.Write "<tr><td>Enter POP3 Mail Host:<td><input type=text size=45 name=host value=""" & strHostName & """>"
    Response.Write "<tr><td>Enter POP3 User Name:<td><input type=text size=45 name=uid value=""" & strUser & """>"
    Response.Write "<tr><td>Enter POP3 Password:<td><input type=password size=45 name=pwd value=""" & strPassword & """>"
    Response.Write "<input type=""Submit"">"
    Response.Write "</form>"
    Response.Write "</table>"

  end sub

  rem ******************************************
  rem * Get the list of all message headers and
  rem *  display the info to the client
  rem ******************************************
  
  sub ShowMessageList (strHost, strUid, strPwd)
    Set Mailer = Server.CreateObject("POP3svg.Mailer")
    Mailer.RemoteHost  = strHost
    Mailer.UserName = strUid
    Mailer.Password = strPwd
   Response.Write "<p align=center><B>&#272;&#258;NG KÝ CÔNG V&#258;N &#272;&#7870;N T&#7914; <font color=blue>MAIL</font></B>"	    
    if Mailer.GetPopHeaders then
      Response.Write "<table border=0 width=""100%"" style='BORDER-BOTTOM-STYLE: solid; BORDER-LEFT-STYLE: solid; BORDER-RIGHT-STYLE: solid; BORDER-TOP-STYLE: solid;Border-color:#C0C0C0'>" & VbCrLf
      Response.Write "<tr bgcolor=#173584>" & VbCrLf
      Response.Write "<td align=center  bgcolor=#BDD5D0><b>STT</b></td>" & VbCrLf
      Response.Write "<td align=center  bgcolor=#BDD5D0><b>" & "Ch&#7911; &#273;&#7873;" & "<b></td>" & VbCrLf
      Response.Write "<td align=center  bgcolor=#BDD5D0><b>" & "Ngày gi&#7901;" & "<b></td>" & VbCrLf
      Response.Write "<td align=center  bgcolor=#BDD5D0><b>" & "T&#7915;" & "<b></td>" & VbCrLf

      rem Response.Write "<td align=center  bgcolor=#BDD5D0><b>" & "Ng&#432;&#7901;i g&#7917;i" & "<b></td>" & VbCrLf
      rem Response.Write "<td align=center  bgcolor=#BDD5D0><b>" & "Ng&#432;&#7901;i nh&#7853;n" & VbCrLf
      rem Response.Write "<td align=center  bgcolor=#BDD5D0><b>" & "Reply-To" & "<b></td>" & VbCrLf

      Response.Write "<td align=center  bgcolor=#BDD5D0><b>" & "Kích th&#432;&#7899;c" & "<b></td>" & VbCrLf
      Response.Write "<td align=center  bgcolor=#BDD5D0><b>" & "Xoá" & "<b></td>" & VbCrLf
      Response.Write "</tr>" & VbCrLf

      varArray = Mailer.MessageInfo
      if VarType(varArray) <> vbNull And IsEmpty(varArray) <>  True then
        ArrayLimit = UBound(varArray)
        'For I = 0 to ArrayLimit
		For I = ArrayLimit to 0 step -1
	        if (i/2=int(i/2)) then
				color="#eeeecc"
			else
				color="#F8F9D9"
			end if

          Response.Write "<tr  style='BACKGROUND-COLOR: " & color &"'>"          
          strMsgNo = Trim(varArray(I)(0))
		  mSTT = ArrayLimit-I+1

          rem the random number is to prevent the browser from thinking that the
          rem   page is cached when you try and delete the same message number
          Randomize
          intRndNo = Int(500 * Rnd)
          'Response.Write "<td >" & strMsgNo & "</td>"
		  Response.Write "<td >" & mSTT  & "</td>"		  

          strSubject = varArray(I)(1)
          if strSubject = "" then strSubject = "(No Subject)"
          
	      bSubject=VietCodeToUnicode(bArray,FixUpItems (strSubject))

          Response.Write "<td align=left>" & "<a href=Openmail.asp?msgno=" & strMsgNo & "&rndno=" & intRndNo & ">" & bSubject & "</a></td>" & VbCrLf

          Response.Write "<td align=left>" & varArray(I)(2) & "</td>" & VbCrLf

          Response.Write "<td align=left>" & FixUpItems (varArray(I)(3)) & "</td>" & VbCrLf

          rem skip the sender field for this demo
          rem Response.Write "<td align=left>" & FixUpItems (varArray(I)(4)) & "</td>" & VbCrLf

          rem skip the to field for this demo
          rem Response.Write "<td align=left>" & FixUpItems (varArray(I)(5)) & "</td>" & VbCrLf

          rem skip the reply-to field for the demo
          rem Response.Write "<td align=left>" & FixUpItems (varArray(I)(6)) & "</td>"

          Response.Write "<td align=left>" & varArray(I)(7) & "</td>"

          Response.Write "<td align=left>" & "<a href=openmail.asp?deletemsg=" & strMsgNo & "&rndno=" & intRndNo & ">Xoá</a></td>"
          Response.Write "</tr>" & Chr(10) & Chr(13)
        Next
      else
        Response.Write "<tr><td colspan=10 align=center><b>No messages on server</b></tr>"
      end if
      Response.Write "</table><center><p><br>"
      Response.Write "<a href=""Openmail.asp?rndno=" & intRndNo & """>Refresh</a></center>"
    else
      Response.Write "<p>Connection Failure. Check your mailhost, username and password."
    end if
    Response.Write "</blockquote>"
  end sub

  rem ******************************************
  rem * Shows the text for one specific message
  rem ******************************************
  sub ShowMessage(strHost, strUid, strPwd, strMsgNo)
    Set Mailer = Server.CreateObject("POP3svg.Mailer")
    strMailBaseDir =server.MapPath("..\Xuly\temp")
    Mailer.MailDirectory = strMailBaseDir
    Mailer.RemoteHost = strHost
    Mailer.UserName   = strUid
    Mailer.Password   = strPwd
    Mailer.OpenPop3
    Mailer.Pop3Log = "c:\pop3log.txt"
    Mailer.Retrieve strMsgNo
    Mailer.ClosePop3
    bBody=VietCodeToUnicode(bArray,Mailer.BodyText)
    bSubject=VietCodeToUnicode(bArray,FixUpItems(Mailer.Subject))
    Response.Write "<form name=frm method=post action='frmvtden.asp?bComm=add&bSendfrom=mail&MsgNo="& strMsgNo &"'>"    
    Response.Write "<textarea name=TxtBody style='visibility:hidden;position:absolute;top:0px;left:0px'>"&  bBody &"</textarea>"
    Response.Write "<input name=TxtSubject type=hidden value='"& bSubject  &"'>"
    Response.Write "<p align=center ><input name=CmdOK type=submit value='&#272;&#259;ng ký công v&#259;n &#273;&#7871;n t&#7915; Mail' style='font-family: Arial;'>"
    Response.Write "<table border=1 width=""100%"">" 
    Response.Write  "<tr>"
    Response.Write  "<td>"
    Response.Write  "<p align=center>Nội dung"
    Response.Write  "</td>"
    Response.Write  "</tr>"    
    Response.Write  "<tr>"
    Response.Write  "<td>"
    Response.Write  "<pre>"
    Response.Write bBody
    Response.Write  "</pre>" 
    Response.Write  "</td>"
    Response.Write  "</tr>"
    Response.Write  "</table>"

    if Mailer.AttachmentCount > 0 then
      Response.Write "<table border=1 width=""100%"">" & VbCrLf
      Response.Write "<tr><td>Tệp gắn kèm</td><td>Kiểu</td><td>Tên</td><td>Kích thước</td></tr>" & VbCrLf
      For intCount = 1 to Mailer.AttachmentCount
        if Mailer.GetAttachmentInfo (intCount) then
          Response.Write "<tr><td><a href='../xuly/temp/"& Mailer.AttFileName &"' target='_blank'>" & intCount & "</a></td><td><a href='../xuly/temp/"& Mailer.AttFileName &"' target='_blank'>" & Mailer.AttContentType & "</a></td><td><a href='../xuly/temp/"& Mailer.AttFileName &"' target='_blank'>" & Mailer.AttFileName & "</a></td><td><a href='../xuly/temp/"& Mailer.AttFileName &"' target='_blank'>" & Mailer.AttFileSize & "</a></td></tr>" & VbCrLf
          Mailer.SaveAttachment (intCount)
        end if
      Next
      Response.Write "</table>" & VbCrLf
    end if
    Response.Write "</form>"
  end sub

  rem ******************************************
  rem * DELETE the message PERMANENTLY from the
  rem *  server
  rem ******************************************
  sub DeleteMessage (strHost, strUid, strPwd, strMsgNo)
    Set Mailer = Server.CreateObject("POP3svg.Mailer")

    Mailer.RemoteHost = strHost
    Mailer.UserName   = strUid
    Mailer.Password   = strPwd
    Mailer.OpenPop3

    rem We could do multiple deletes here but this demo only does 1. You must
    rem  close the server at this point or our message numbers in
    rem  ShowMessageList won't be correct.

    Mailer.Delete strMsgNo
    Mailer.ClosePop3

    ShowMessageList strHost, strUid, strPwd
  end sub
' main 
	sSQL="Select * from config"
	Set RecConf=server.createObject("ADODB.Recordset")
	RecConf.cursortype=3
	RecConf.Cachesize=5
	RecConf.open sSQL,Conn
	if RecConf.recordcount then
	    Session("hostMail")=recconf("Pop3IPMail")
		Session("uidMail")=recconf("Pop3Username")
		Session("pwdMail")=recconf("Pop3Password")
	  	strHost       = Session("hostMail")
  		strUid        = Session("uidMail")
		strPwd        = Session("pwdMail")
  		strMsgNo      = Request.QueryString("msgno")
  		strDeleteNo   = Request.QueryString("deletemsg")
  		if (strUid = "") or (strPwd = "") or (strHost = "") then
    			ShowPopForm strHost, strUid, strPwd
  		else
    			if (strMsgNo <> "") then
      			ShowMessage strHost, strUid, strPwd, strMsgNo
    			else
      			if (strDeleteNo <> "") then
        				DeleteMessage strHost, strUid, strPwd, strDeleteNo
      			else
        				ShowMessageList strHost, strUid, strPwd
      			end if    
    			end if
  		end if
  	end if
%>
</body>
</html>
</body>
</html>